<template>
	<uni-card>
		<uni-forms ref="form" :rules="rules" :modelValue="formData" labelWidth="100px">
			<uni-forms-item required label="姓名" name="name">
				<uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
			</uni-forms-item>
			<uni-forms-item label="性别" required>
				<uni-data-checkbox v-model="formData.sex" :localdata="sexs" />
			</uni-forms-item>
			<uni-forms-item label="手机号码" required>
				<uni-easyinput v-model="formData.phone" placeholder="请输入手机号码"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="工作单位" required>
				<uni-easyinput v-model="formData.workUnit" placeholder="请输入工作单位"></uni-easyinput>
			</uni-forms-item>
		</uni-forms>
		<button @click="submitForm">确认</button>
	</uni-card>
</template>

<script setup lang="ts">
	import {
		ref,
		onMounted
	} from 'vue'
	import {
		useUserStore,
	} from '@/store'
	import api from '@/api'
	const userStore = useUserStore()
	const userInfo = userStore.userInfo
	const formData = ref({
		username: '',
		name: '',
		sex: '',
		phone: '',
		workUnit:'',
	})
	const form = ref()
	const rules = ref()
	const sexs = ref([{
		text: '男',
		value: '男'
	}, {
		text: '女',
		value: '女'
	}], )
	onMounted(() => {
		getSpecialistInfo()
	})
	const getSpecialistInfo = () => {
		api.specialist.info().then(res => {
			let tmp = res.data.data
			Object.keys(tmp).forEach((key: string | number) => {
				console.log(key)
				formData.value[key]=tmp[key]
			})
		})
	}
	const submitForm = () => {
		api.specialist.update(formData.value).then((res => {
			if (res.data.code === 0) {
				uni.switchTab({
					url: '/pages/user/mine/mine',
					success: () => {
						uni.showToast({
							icon: 'success',
							title: res.data.msg,
						})
					}
				})

			}
		}))
	}
</script>

<style>
</style>
